package com.zh.media.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.PowerManager;

/**
 * @Description:  熄屏亮屏幕
 * @Author:         mark
 * @CreateDate:     2025/1/6 21:33
 * @UpdateUser:     更新者：
 * @UpdateDate:     2025/1/6 21:33
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */
public class ScreenController {

    private PowerManager powerManager;
    private PowerManager.WakeLock wakeLock;

    public ScreenController(Context context) {
        this.powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        this.wakeLock = null;
    }

    @SuppressLint("InvalidWakeLockTag")
    public void turnScreenOn() {
        if (wakeLock == null) {
            wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyWakeLock");
        }
        if (!wakeLock.isHeld()) {
            wakeLock.acquire();
        }
    }

    public void turnScreenOff() {
        if (wakeLock != null && wakeLock.isHeld()) {
            wakeLock.release();
        }
    }
}
